{% extends "dashboard/base.html" %}
{% load i18n %}
{% load materializecss %}
{% load staticfiles %}

{% block title %}
  {% if attribute.pk %}
    {{ attribute }}
  {% else %}
    {% trans "Add new attribute" context "Attribute detail page title" %}
  {% endif %}
  - {% trans "Attributes" context "Dashboard attributes list" %} - {{ block.super }}
{% endblock %}

{% block body_class %}body-attributes{% endblock %}

{% block menu_attributes_class %}active{% endblock %}

{% block header_menu %}
  {% url "dashboard:product-attributes" as url %}
  {% include "dashboard/includes/_back-link.html" with url=url %}
{% endblock %}

{% block header_extra %}
  {% if attribute.pk %}
    <a class="dropdown-button right" href="#" data-activates="attribute-delete" data-constrainwidth="false">
      <svg data-src="{% static "dashboard/images/more_vert.svg" %}" height="24" width="24" />
    </a>
    <ul id="attribute-delete" class="dropdown-content">
      <li>
        <a class="modal-trigger-custom" href="#base-modal"
        data-href="{% url 'dashboard:product-attribute-delete' pk=attribute.pk %}">
          {% trans "Remove attribute" context "Attribute detail action" %}
        </a>
      </li>
    </ul>
  {% endif %}
{% endblock %}

{% block breadcrumbs %}
  <ul class="breadcrumbs breadcrumbs--history">
    <li>
      <a href="{% url 'dashboard:product-attributes' %}" class="breadcrumbs--ellipsed-item">
      {% trans "Attributes" context "Dashboard attributes list" %}
      </a>
    </li>
    <li class="back-mobile">
      <a href="{% url 'dashboard:product-attributes' %}">
        <svg data-src="{% static "dashboard/images/arrow_left.svg" %}" fill="#fff" width="20px" height="20px" />
      </a>
    </li>
    <li>
      <span class="breadcrumbs--ellipsed-item">
        {% if attribute.pk %}
          {{ attribute }}
        {% else %}
          {% trans "Add new attribute" context "Attribute detail breadcrumbs" %}
        {% endif %}
      </span>
    </li>
  </ul>
{% endblock %}

{% block menu_catalogue_class %} active{% endblock %}

{% block content %}
  <div class="row">
    <div class="col m12 l9">
      <div class="card">
        <form method="post" enctype="multipart/form-data" id="form-attributes" novalidate>
          <div class="card-content card-content-form">
            {% csrf_token %}
            <div class="row">
              {{ form.name|materializecss }}
            </div>
            <div class="row">
              {{ form.slug|materializecss }}
            </div>
            <h5 class="card-title">
              {% trans "Attribute values" context "Attribute values formset title" %}
            </h5>
            {{ formset.management_form }}
            {{ formset.non_form_errors.as_ul }}
          </div>
          <div class="formset-table-container">
            <table id="formset" class="formset-table">
              {% for form in formset.forms %}
                {% if forloop.first %}
                  <thead>
                    <tr>
                      {% for field in form.visible_fields %}
                        <th>{{ field.label|capfirst }}</th>
                      {% endfor %}
                    </tr>
                  </thead>
                {% endif %}
                <tr>
                  {% for field in form.visible_fields %}
                    <td{% if forloop.last %} class="center-align"{% endif %}>
                      {% if forloop.first %}
                        {% for hidden in form.hidden_fields %}
                          {{ hidden }}
                        {% endfor %}
                      {% endif %}
                      {{ field|materializecss }}
                    </td>
                  {% endfor %}
                </tr>
              {% endfor %}
            </table>
          </div>
          <div class="card-action right-align">
            {% if attribute.pk %}
              <a href="{% url 'dashboard:product-attributes' %}" class="btn btn-flat">
                {% trans "Cancel" context "Dashboard cancel action" %}
              </a>
              <button type="submit" class="btn waves-effect waves-light">
                {% trans "Update" context "Dashboard update action" %}
              </button>
            {% else %}
              <a href="{% url 'dashboard:product-attributes' %}" class="btn btn-flat">
                {% trans "Cancel" context "Dashboard cancel action" %}
              </a>
              <button type="submit" class="btn waves-effect waves-light">
                {% trans "Create" context "Dashboard create action" %}
              </button>
            {% endif %}
          </div>
        </form>
      </div>
    </div>
    <div class="col m12 l3 help-box"></div>
  </div>
{% endblock %}
